<template>
  <a-modal
    title="商户管理"
    :width="640"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :maskClosable="false"
    @ok="handleSubmit"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="积分">
          <a-input placeholder="积分" v-decorator="[ 'integral', {rules: [{ required: true, message: '请输入。。。' }] }]"/>
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="描述">
          <a-textarea placeholder="描述" v-decorator="['description', {rules: [{ required: true, message: '请输入。。。' }]} ]" :rows="4"/>
        </a-form-item>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import pick from 'lodash.pick'
  import { additionalIntegral } from '@/api/shop/member'

  export default {
    data () {
      return {
        baseUrl: process.env.VUE_APP_API_BASE_URL,
        id: null,
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        visible: false,
        confirmLoading: false,
        isDisabled: false,
        form: this.$form.createForm(this)
      }
    },
    mounted () {

    },
    methods: {
      add () {
        this.visible = true
      },
      edit (record) {
        this.id = record.id
        this.visible = true
      },
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            values.id = this.id
            additionalIntegral(values).then((res) => {
              this.confirmLoading = false
              if (res.code === 200) {
                this.handleCancel()
                this.$emit('ok')
              }
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      handleCancel () {
        this.visible = false
        this.form.resetFields()
        this.id = null
      },
    }
  }
</script>
